package org.example.面向过程;

import com.mysql.cj.jdbc.Driver;

import java.sql.*;

//包名不推荐，仅作学习
public class DemoA {
    public static void main(String[] args) {
        //第一步：加载驱动
        try {
            Class.forName(Driver.class.getName());
        }catch (ClassNotFoundException e){
            System.out.println("驱动文件没有找到！");
        }
        try {
            //第二步：建立连接
            String url = "jdbc:mysql://localhost:3306/bd200521?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
            String username = "root";
            String password = "a123456";
            Connection conn = DriverManager.getConnection(url,username,password);
            //第三步：创建一个传令官(邮递员)
            String sql = "insert into users values(null,'马六','女','116112','陕西西安','36')";
            PreparedStatement ps = conn.prepareStatement(sql);
            //第四步：传输到MYSQL中执行
            int resultNum = ps.executeUpdate();
            System.out.println(resultNum);
            //第五步：关闭数据库连接
            ps.close();
            conn.close();
        }catch (SQLException e){
            System.out.println(e.getMessage());
        }
    }
}
